import java.util.Scanner;

public class Main2 {

    public static int qiuzuida(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        int max1 = nums[0];
        int max2 = nums[0];

        for (int i = 1; i < nums.length; i++) {
            max2 = Math.max(nums[i], max2 + nums[i]);
            max1 = Math.max(max1, max2);
        }

        return max1;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入数组的长度:");
        int length = scanner.nextInt();
        int[] nums = new int[length];

        System.out.println("请输入" + length + "个整数:");
        for (int i = 0; i < length; i++) {
            nums[i] = scanner.nextInt();
        }

        int maxSum = qiuzuida(nums);
        System.out.println("最大和: " + maxSum);

        scanner.close();
    }
}